package com.it.park.rms.listener;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class SystemListener implements ServletContextListener{

	@Override
	public void contextInitialized(ServletContextEvent sce) {
		try {
			System.out.println("----启动");
			ServletContext context = sce.getServletContext();
			System.out.println(context.getRealPath("/"));
			String path = context.getRealPath("/");
			String rootPath = new File(new File(path).getParent()).getParent();
			System.out.println(rootPath);
			String licPath = rootPath+"\\conf\\license.lic";
			if(!new File(licPath).exists()){
				System.out.println("----启动失败，系统license不存在");
//				return;
//				throw new RuntimeException("----启动失败，系统license不存在");
			}
			InputStream is =  context.getResourceAsStream(licPath);
			byte[] bytes = new byte[is.available()];
			StringBuilder builder = new StringBuilder();
			builder.append(new String(bytes));
			is.close();
			System.out.println(builder.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
		ServletContextListener.super.contextInitialized(sce);
	}

}
